package cn.kickegg.leetcode;

/**
 * @author KickEGG
 * @createTime 2018-08-02 14:05
 * @Description
 */
public class SumTest1 {

  public static void main(String[] args) {
    int[] result = findTwoSum(new int[]{1, 3, 5, 7, 9}, 12);


    System.out.println(result[0] + " /" + result[1]);
  }

  // 说明：本例中应返回1,4(3 + 9 == 12)
  static int[] findTwoSum(int[] list, int sum) {
    int i, j = 0;
    int[] result = new int[2];

    outterLoop:
    for (i = 0; i < list.length; i++) {
      for (j = i + 1; j < list.length; j++) {
        // 只要有符合条件的就返回
        if (list[i] + list[j] == sum) {
          result[0] = i;
          result[1] = j;
          System.out.println("i=" + i + " j=" + j);
          return result;

        }
      }
    }
    // 无解,返回null
    return null;
  }

}
